import { request, jsonParams } from './utils.js';

export const jsonHeader = {
    'Content-Type': 'application/json',
};
export const formHeader = {
    Accept: '*/*',
    'Access-Control-Allow-Origin': '*',
};


class RequestHttp {
    url = "/"
    constructor() {

    }
    get(url, options = {}) {
        const { params, headers = {} } = options
        const paramss = params ? "?"+jsonParams(params) : ""
        return request({ url: url + paramss, method: 'GET', headers: headers })
    }
    post(url, options = {}) {
        const { data, headers = {} } = options
        return request({ url, method: 'POST', headers: headers, data })
    }
    delete(url, options = {}) {
        const { data, headers = {} } = options
        return request({ url, method: 'DELETE', headers: headers, data })
    }
    upload(url, options = {}) {//上传文件
        const { data } = options
        const formData = new FormData();
        formData.append('file', data.file); // 将文件添加到FormData
        return request({ url, method: 'POST', formData })
    }
}
export const requests = new RequestHttp();